home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d18
/
tpdb13.arc
/
TPDB.DOC
< prev
next >
Wrap
Text File
|
1989-02-13
|
30KB
|
1,208 lines
(***********************************)
(* TPDB *)
(* Turbo Pascal Tools for dBASE *)
(* *)
(* Turbo Pascal 5.0 Unit *)
(* for Accessing dBASE III *)
(* files. *)
(* *)
(* Copyright 1989 *)
(* Brian Corll *)
(* *)
(* All Rights Reserved *)
(* dBASE is a registered *)
(* trademark of Ashton-Tate, Inc. *)
(* *)
(* Turbo Pascal is a registered *)
(* trademark of Borland Int. Corp.*)
(* *)
(* Version 1.3 February 14, 1989 *)
(* *)
(***********************************)
This Turbo Pascal 5.0 TPU allows you to access,search,
read and write database files that were created with
dBASE III or III Plus, using 55 precompiled procedures
and functions written specifically for these purposes.
At present, it supports only a single .DBF and an
associated index (it's own brand ofindexes, NOT indexes
created by dBASE) . Index keys can be up to 254
characters, but must be a single character or numeric
field. No multiple keys are allowed. Future plans
include support for multiple indexes and multiple index
keys, as well as multiple .DBF files open concurrently.
All field types are supported except memo fields.
Questions/comments can be left for me on the InterLink
or FidoNet Pascal or dBASE conferences.
This program is being distributed under the Shareware
concept.
If you like this program and use it, a registration fee
of $10 is requested for non-profit users. Commercial
users MUST register for a one-time, royalty-free
registration fee of $15. Registered users will be
entitled to upgrades for a fee of $5 per upgrade, to
cover shipping and handling costs. See the file
REGISTER.FRM.
Write to:
Ten B.C. Micro Systems
Brian Corll
102 West Locust Street
Mechanicsburg,PA 17055
Home : 717-691-0286 Eves. and Weekends
DISCLAIMER
This program is provided "as is" without warranty of any
kind, either express or implied, included but not
limited to the implied warranty of merchantability and
fitness for a specific purpose. The entire risk as to
the quality and performance of this program is with you.
In no event will the author be liable to you for any
damages, including any lost profits, lost savings or
other incidental or consequential damages arising out of
the use of or inability to use this program.
(***************************************************)
(* Globals in TPDB.tpu *)
(***************************************************)
The globals in this TPU use up only 862 bytes of the
data segment !
Const
CursorLeft = ^S;
CursorRight = ^D;
CursorDown = ^X;
CursorUp = ^E;
CursorHome = ^A;
CursorEnd = ^F;
PageUp = ^R;
PageDown = ^C;
DelKey = ^G;
TabKey = #9;
Return = ^M;
Escape = ^[;
UpperCase : Boolean = False;
NoDuplicates = 0;
Duplicates = 1;
MaxReal = 3.4E37;
MinReal = 1.5E-45;
MaxLong = 2147483647;
MinLong = -2147483647;
The following are color constants to be used with Normal
and Reverse to set display and edit colors, using Turbo
Pascal's constant folding capabilities.
e.g. to display fields in white on a blue background you
would set Normal := White+BlueBG; to edit in black on a
white background you set Reverse := Black+LightGrayBG.
Black = $00; DarkGray = $08;
Blue = $01; LightBlue = $09;
Green = $02; LightGreen = $0A;
Cyan = $03; LighBCyan = $0B;
Red = $04; LightRed = $0C;
Magenta = $05; LightMagenta = $0D;
Brown = $06; Yellow = $0E;
LightGray = $07; White = $0F;
Blink = $80;
BlackBG = $00;
BlueBG = $10;
GreenBG = $20;
CyanBG = $30;
RedBG = $40;
MagentaBG = $50;
BrownBG = $60;
LightGrayBG = $70;
Type
Str2 = String[2];
Str4 = String[4];
Str5 = String[5];
Str6 = String[6];
Str8 = String[8];
Str10 = String[10];
Str15 = String[15];
Str20 = String[20];
Str30 = String[30];
Str60 = String[60];
Str80 = String[80];
Str132 = String[132];
CharSet = Set of Char;
ByteSet = Set of Byte;
FileName = String[66];
DBRecPtr = ^DBType;
DBType = Array[1..4000] of Char;
DBKey = String[254];
DBHeader = Record
DBType : Byte;
Year : Byte;
Month : Byte;
Day : Byte;
RecCount : LongInt;
Location : Integer;
RecordLen : Integer;
Reserved : Array[1..20] of Byte;
Terminator : Char;
end;
DBField = Record
FieldName : Array[1..11] of Char;
FieldType : Byte;
FieldAddress : LongInt;
FieldLen : Byte;
FieldDec : Byte;
Reserved : Array[1..14] of Char;
end;
HeadPtr = ^DBHeader;
PosPtr = ^DBEditArray;
FieldPtr = ^FieldArray;
DBEditArray = Array[1..2,1..128] of Integer;
FieldArray = Array[1..128] of DBField;
Const
Up : CharSet = [CursorUp];
Down : CharSet = [CursorDown,Return];
Next : CharSet = [Escape];
Var
Normal : Byte;
Reverse : Byte;
UCKey,IndOpen,
DBFOpen : Boolean;
DBFileName : FileName;
DBFile,TempFile : File;
Header : HeadPtr;
Fields : FieldPtr;
Message : String[80];
Positions : PosPtr;
DBRecord : DBRecPtr;
NumFields,ErrCode : Integer;
BC,Ch : Char;
TotalRecs,DBRecNum,
: LongInt;
Y,M,D,DW : Word;
NumLen,Decimals,
LL,K : Byte;
DBIndex : IndexFile;
DBIndexName : FileName;
Found : Boolean;
Start,Stop : Integer;
(************************************************************)
(* Documentation for Procedures and Functions in TPDB.tpu *)
(************************************************************)
AddDBKey procedure
Function
Adds a key string to the index currently in use.
Declaration
AddDBKey(FieldNumber : Byte);
Remarks
FieldNumber is the number of the field in the order of fields
in the .DBF file structure.
Restrictions
FieldNumber must be a valid field number in the range 1..128.
*************************
AddDBRec procedure
Function
Adds a new record to the .DBF file in use.
Declaration
AddDBRec;
Remarks
A new record must first be created with a call to the
NewDBRec procedure.
************************
Block procedure
Function
Turns on a block cursor.
Declaration
Block;
************************
BOF function
Function
Returns beginning of file status of a .DBF file.
Declaration
BOF
Result Type
Boolean
************************
BuildIndex procedure
Function
Creates and builds an index file to be associated
with a .DBF file.
Declaration
BuildIndex(IndexName : FileName;FNo :
Byte;KeyLen,Status : Integer);
Remarks
IndexName can be a maximum of 66 chars in length
and is the full path and name of the index file to
be created.
FNo is the number of the field in the .DBF
structure to be used as the key field.
KeyLen is the length of the key field. Number are
stored as strings in .DBF files, and can thus be
used as keys without conversion.
Status is defined as one of two constants:
NoDuplicates, or Duplicates, according to whether
or not duplicate keys will be allowed in the
index.
************************
CheckScreen procedure
Function
Checks the current field being edited against
minimum and maximum limits of fields displayed.
Declaration
CheckScreen(Var CurrPos:Byte;BC:Char;Up,Down:CharSet;
Low,High:Byte);
Remarks
CurrPos is the number of the field currently being
edited in the editing loop (see DEMO.pas for an
example).
BC is the terminating character when field editing
has been completed.
Up and Down are the character sets which contain
the terminating characters which allow you to move
from one field to another, up or down. In TPDB,
they are declred as constants, as follows:
Up : CharSet = [CursorUp];
Down : CharSet = [CursorDown,Return];
I first saw this concept used by Juan Vegarra in
his DER.pas data entry routines.
Low and High are the low and high numbers of the
displayed fields.
************************
CloseDBFile procedure
Function
Closes the currently open .DBF file.
Declaration
CloseDBFile;
Remarks
This procedure is error-checked.
************************
CloseDBIndex procedure
Function
Closes the index currently in use.
Declaration
CloseDBIndex;
Remarks
This procedure is error-checked.
************************
DBOpenFile procedure
Function
Opens a .DBF file.
Declaration
DBOpenFile(DBName : FileName);
Remarks
FileName can be up to 66 chars long and can
contain the full path.
This procedure is error-checked.
************************
DBReset procedure
Function
Resets a .DBF file, moving the file pointer to
record 1.
Declaration
DBReset;
Remarks
This procedure is error-checked.
************************
DelDBKey procedure
Function
Deletes a key string in the index currently in use.
Declaration
DelDBKey(FieldNumber : Byte);
Remarks
FieldNumber is the number of the field in the
order of fields in the .DBF file structure.
Restrictions
FieldNumber must be a valid field number in the
range 1..128.
*************************
Deleted function
Function
Returns True if the curent record has been marked
for deletion, False if it has not been marked.
Declaration
Deleted : boolean;
************************
Display procedure
Function
Displays the current record in a partially
formatted manner.
Declaration
Display;
Remarks
Date fields are formatted as MM/DD/YY.
*************************
EOF function
Function
Returns end-of-file status of a .DBF file.
Declaration
EOF
Return Type
Boolean
************************
FieldToStr function
Functions
Returns a string read from a specified field in a
specified record in a .DBF file.
Declaration
FieldToStr(FieldNumber : Byte) : string;
Remarks
FieldNumber is the number of the field in the .DBF
file structure. Date fields are not formatted.
************************
FillRecs procedure
Function
Appends a specified number of blank records to a
.DBF file.
Declaration
FillRecs(NumRecs : LongInt);
************************
Find procedure
Function
Searches for a string in the currently open index.
Declaration
Find(SearchStr : String);
Remarks
If the string is found, a value of True is
returned in the global boolean variable Found. If
the string is not found, a value of False is
returned in Found.
************************
Flash procedure
Function
Writes a string at a specified row and column,
using a specified attribute, by direct video
access.
Declaration
Flash(Row,Col, Attr:byte; Str : String);
Remarks
When setting attribute, constant folding can be
used. See color constants in globals section.
************************
FlashC procedure
Function
Writes a centered string at a specified row, using
a specified attribute, by direct video access.
Declaration
FlashC(Row,Attr:Byte;Str : String);
Remarks
See remarks for Flash procedure.
************************
FlashFill procedure
Function
Fills a specified screen block with a specified
character and attribute.
Declaration
FlashFill(Row,Col,Rows,Cols,Attr : Byte;Ch :
Char);
Remarks
See remarks for other Flash procedures.
************************
FlushDB procedure
Function
Flushes records currently in memory to disk file.
Declaration
FlushDB;
Remarks
This procedure is error-checked.
************************
Get procedure
Function
Edits a specified field in the .DBF at a specified
row and column.
Declaration
Get(FieldNumber,Row,Col : Byte);
Remarks
The following editing keys are active:
Left cursor
Right Cursor
Home
End
Ctrl-Y (Deletes the entire field.)
************************
GetDBRec procedure
Function
Locates and reads a specified record in a .DBF
file.
Declaration
GetDBRec(RecordNumber : LongInt);
************************
GetString procedure
Function
Allows screen input of a string, as in a search
procedure.
Declaration
GetString(Var Parameter : String; Length, Row, Col
: Byte) : Char;
************************
GoBottom procedure
Function
Set the file pointer at the end of file.
Declaration
GoBottom;
************************
GoTop procedure
Function
Sets the file pointer at the beginning of file.
Declaration
GoTop;
************************
IIF function
Function
Evaluates a boolean variable and returns a string
according to the value of the boolean.
Declaration
IIF(BoolVar : Boolean;IfTrue,IfFalse : String) :
String;
************************
JustL function
Function
Left justifies a string within a specified field
length.
Declaration
JustL(InString: String; FieldLen: Integer): String;
************************
LTrim function
Function
Trims leading spaces from a string.
Declaration
LTrim(InStr: String): String;
************************
MakeDBIndex procedure
Function
Creates a new index file but does not build it.
Declaration
MakeDBIndex(DBIndexName : FileName;KeyLen,Status :
Integer);
Remarks
DBIndexName can be a maximum of 66 chars in length
and is the full path and name of the index file to
be created. the key field.
KeyLen is the length of the key field. Number are
stored as strings in .DBF files, and can thus be
used as keys without conversion.
Status is defined as one of two constants:
NoDuplicates, or Duplicates, according to whether
or not duplicate keys will be allowed in the
index.
************************
Mark procedure
Function
Marks the current record for deletion.
Declaration
Mark;
************************
NewDBRec procedure
Function
Creates a new blank record in memory, ready for
editing.
Declaration
NewDBRec;
************************
NextDBKey procedure
Function
Moves file record pointer to the record number
associated with the next key in an index.
Declaration
NextDBKey(FieldNumber : Byte);
Remarks
FieldNumber is the number of the field in the .DBF
file structure.
************************
NextRec procedure
Function
Moves the file pointer to the next sequential
record in the file.
Declaration
NextRec;
************************
OpenDBIndex procedure
Function
Opens an index for search and updating.
Declaration
OpenDBIndex(DBIndexName : FileName;KeyLen,Status :
Integer);
Remarks
DBIndexName can be a maximum of 66 chars in length
and is the full path and name of the index file to
be created. the key field.
KeyLen is the length of the key field. Number are
stored as strings in .DBF files, and can thus be
used as keys without conversion.
Status is defined as one of two constants:
NoDuplicates, or Duplicates, according to whether
or not duplicate keys will be allowed in the
index.
************************
Pack procedure
Function
Packs a .DBF files, removing records marked for
deletion.
Declaration
Pack;
************************
PadL function
Function
Pads a string with spaces on the left, to a
specified field length.
Declaration
PadL(InStr: String; FieldLength: Integer): String;
************************
PadR function
Function
Pads a string with spaces on the right, to a
specified field length.
Declaration
PadR(InStr: String; FieldLength: Integer): String;
************************
PrevDBKey procedure
Function
Moves file pointer to the record number
corresponding to the previous key in an index.
Declaration
PrevDBKey(FieldNumber : Byte);
Remarks
FieldNumber is the number of the field in the .DBF
file structure.
************************
PrevRec procedure
Function
Moves the file pointer to the previous sequemtial
record in the file.
Declaration
PrevRec;
************************
Prompt procedure
Function
Displays a prompt string at a specified row an
column, using direct video writes.
Declaration
Prompt(Row,Col : Byte;PromptStr : Str80);
************************
PutDBRec procedure
Function
Writes the current editing record to a specified
record number in the .DBF file.
Declaration
PutDBRec(RecordNumber : LongInt);
Remarks
Be sure that the specified record number is the
same as the one given in the call to GetDBRec.
************************
ReadDBHeader procedure
Function
Reads the file header of a .DBF file into a
buffer.
Declaration
ReadDBHeader;
************************
Recall procedure
Function
Unmarks a record previously marked for deletion.
Declaration
Recall;
************************
Repl procedure
Function
Replaces a specified field in a record with a
specified string.
Declaration
Repl(FieldNumber : Byte;ReplStr : string);
Remarks
FieldNumber is the number of the field in the .DBF
file structure. ReplStr is the string with which
the field is to be replaced. When replacing date
fields, remember that the date string must be in
the form "19890214".
************************
ReplEach procedure
Function
Replaces a specified field in each record in a
.DBF file with a specified string.
Declaration
ReplEach(FieldNumber : Byte;ReplStr : String);
Remarks
FieldNumber is the number of the field in the .DBF
file structure. ReplStr is the string with which
the field is to be replaced. When replacing date
fields, remember that the date string must be in
the form "19890214".
************************
Replicate function
Function
Fills a string with a specified number of a
specified character.
Declaration
Replicate(Ch : Char;Count : word) : String;
************************
RTrim function
Function
Trims trailing blanks from a string.
Declaration
RTrim(InStr: String): String;
************************
Say procedure
Function
Displays a particular field at a specified row and
column.
Declaration
Say(FieldNumber,Row,Col : Byte);
Remarks
FieldNumber is the position of the field in the
.DBF file structure.
************************
SetColor
Function
Sets foreground and background color before a call
to ClrScr.
Declaration
SetColor(FG,BG : Byte);
************************
ShowStatus procedure
Function
Displays status of .DBF file, after a call to
ReadDBHeader.
Declaration
ShowStatus;
************************
Sum function
Function
Sums a numeric field in all records in a .DBF
file.
Declaration
Sum(FNo : Byte) : Real;
************************
Upper function
Function
Converts a string to upper case.
Declaration
Upper(InStr: String): String;
************************
Wait procedure
Function
Displays a prompt, 'Press any key to continue...',
and waits for a key press.
Declaration
Wait;
************************
WriteDBHeader procedure
Function
Updates a .DBF file header.
Declaration
WriteDBHeader;
************************
Zap procedure
Function
Deletes all records in a .DBF file.
Declaration
Zap;
Remarks
CAREFUL ! This procedure really does remove all
records, completely rewriting the file.
************************
(**** Revision History ****)
2/7/89 - Version 1.0 released
2/8/89 - Version 1.1 - fixed bug in numeric input that
caused truncation of integers. Also, recompiled in
$N-,$E+ state to allow for 8087 emulation on non-8087
machines. Fixed range error in array indexing.
Renamed unit TPDB10.tpu to TPDB.tpu. Future versions
will retain this name.
2/10/89 - Version 1.2 - Modified indexing routines to
allow for index keys up to 254 characters.
Added boolean variable, UCKey, which allows indexes to
be created on upper case form of keys.
Added procedures Prompt and Upper.
Added procedures Flash, FlashC, and FlashFill.
Added CheckScreen procedure.
Expanded documentation and added demo files.
Temporarily removed source code from this doc file
pending further additions and decision on which source
to include.
2/14/89 - Version 1.3 - Added TPDB error handler.
Improved documentation.
Fixed bug in Display procedure.
Added Sum and FieldToStr functions, NextRec and
PrevRec procedures.
Added BOF and EOF functions.
Added PrevDBKey and NextDBKey procedures.
Added Repl and ReplEach procedures.
Added FillRecs procedure.